/*
 * Background Flickr: Copyright (C) 2009  Craig McNicholas
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.ddw.app.bflickr.imaging;

import android.content.Context;

/**
 * Factory class to generate image collector instances to help
 * in downloading images or returning them from the cache
 * @author craig
 *
 */
public abstract class ImageCollectorFactory {

	/**
	 * creates a new image collector instance for downloading an image from
	 * any url. The collector supports bitmap images only.
	 * @param context the applications context
	 * @param url the url of the image to download
	 * @param ignoreCache whether to ignore any image with the same key in the cache and force the 
	 * method to download the latest copy of the image
	 * @param cacheDownloadedImage whether to cache the image if it is downloaded
	 * @param listener a listener to attach to the object which will trigger events and provide
	 * callbacks to the listener object
	 * @return an image collector instance, you must call <i>start()</li> to trigger the asynchronous 
	 * request
	 */
	public static ImageCollector createInstance(Context context, String url, boolean ignoreCache, boolean cacheDownloadedImage, ImageCollectorListener listener) {
		ImageCollector collector = new ImageCollector(context, url);
		collector.setOverwriteEnabled(ignoreCache);
		collector.setCacheFileOnDownload(cacheDownloadedImage);
		if(listener != null) {
			collector.addListener(listener);
		}
		return collector;
	}
	
	/**
	 * creates a new image collector instance for downloading an image from
	 * any url. The collector supports bitmap images only.
	 * @param context the applications context
	 * @param url the url of the image to download
	 * @param ignoreCache whether to ignore any image with the same key in the cache and force the 
	 * method to download the latest copy of the image
	 * @param cacheDownloadedImage whether to cache the image if it is downloaded
	 * @return an image collector instance, you must call <i>start()</li> to trigger the asynchronous 
	 * request
	 */
	public static ImageCollector createInstance(Context context, String url, boolean ignoreCache, boolean cacheDownloadedImage) {
		return createInstance(context, url, ignoreCache, cacheDownloadedImage, null);
	}
	
	/**
	 * creates a new image collector instance for downloading an image from
	 * any url. The collector supports bitmap images only.
	 * @param context the applications context
	 * @param url the url of the image to download
	 * @param ignoreCache whether to ignore any image with the same key in the cache and force the 
	 * method to download the latest copy of the image
	 * @return an image collector instance, you must call <i>start()</li> to trigger the asynchronous 
	 * request
	 */
	public static ImageCollector createInstance(Context context, String url, boolean ignoreCache) {
		return createInstance(context, url, ignoreCache, true, null);
	}
	
	/**
	 * creates a new image collector instance for downloading an image from
	 * any url. The collector supports bitmap images only.
	 * @param context the applications context
	 * @param url the url of the image to download
	 * @return an image collector instance, you must call <i>start()</li> to trigger the asynchronous 
	 * request
	 */
	public static ImageCollector createInstance(Context context, String url) {
		return createInstance(context, url, false, true, null);
	}
	
	/**
	 * creates a new image collector instance for downloading an image from
	 * any url. The collector supports bitmap images only.
	 * @param context the applications context
	 * @param url the url of the image to download
	 * @param listener a listener to attach to the object which will trigger events and provide
	 * callbacks to the listener object
	 * @return an image collector instance, you must call <i>start()</li> to trigger the asynchronous 
	 * request
	 */
	public static ImageCollector createInstance(Context context, String url, ImageCollectorListener listener) {
		return createInstance(context, url, false, true, listener);
	}
	
}
